package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.EnterFactoryBean;
import com.ukao.steward.util.ActivityUtils;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.MyDateUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/8/24.
 */

public class LeveFactoryAdapter extends ListBaseAdapter<EnterFactoryBean.ListBean> {


    private  int enterType;

    public LeveFactoryAdapter(Context context, List<EnterFactoryBean.ListBean> mHomeBean, int enterType) {
        super(context, mHomeBean);
        this.enterType= enterType;

    }


    @Override
    public int getLayoutId() {
        return R.layout.adapter_lever_factory;
    }


    @Override
    public void onBindItemHolder(SuperViewHolder holder,final int position) {


        EnterFactoryBean.ListBean item = mDataList.get(position);
        TextView factoryName = holder.getView(R.id.factoryName);
        TextView storeName = holder.getView(R.id.storeName);
        TextView code = holder.getView(R.id.code);
        TextView batchText = holder.getView(R.id.batch_text);
        TextView storeTel = holder.getView(R.id.storeTel);
        TextView logisticsWorkTime = holder.getView(R.id.logisticsWorkTime);
        TextView storeWorkTime = holder.getView(R.id.storeWorkTime);
        TextView productCnt = holder.getView(R.id.productCnt);
        LinearLayout logisticsWorkTimeLayout = holder.getView(R.id.logisticsWorkTime_layout);
        LinearLayout storeNameLayout = holder.getView(R.id.storeName_layout);
        LinearLayout storeTelLayout = holder.getView(R.id.storeTel_layout);


        String orderNo = item.getOrderNo();
        if (enterType==3||enterType==4){
            code.setText(orderNo);
            logisticsWorkTime.setText(MyDateUtils.formatDataTime(item.getCreateTime()));
            factoryName.setText(CheckUtils.isEmptyString(item.getStoreName()));
            productCnt.setText(item.getProductCnt() + item.getAnnexCnt() + "");
            storeTel.setText(item.getStoreTel());
            storeName.setText(CheckUtils.isEmptyString(item.getStoreName()));
            storeWorkTime.setText(MyDateUtils.formatDataTime(item.getReachTime()));
        }else{
            code.setText(item.getCode());
            factoryName.setText(item.getFactoryName());
            storeTel.setText(item.getStoreTel());
            storeName.setText(CheckUtils.isEmptyString(item.getStoreName()));
            logisticsWorkTime.setText(MyDateUtils.formatDataTime(item.getLogisticsWorkTime()));
            storeName.setText(item.getStoreName());
            productCnt.setText(item.getProductCnt() + item.getAnnexCnt() + "");
        }





        switch (enterType) {
            case 1:
                logisticsWorkTimeLayout.setVisibility(View.GONE);
                storeNameLayout.setVisibility(View.GONE);


                break;
            case 2:
                logisticsWorkTimeLayout.setVisibility(View.VISIBLE);
                storeNameLayout.setVisibility(View.VISIBLE);
                storeName.setText(CheckUtils.isEmptyString(item.getFactoryName()));
                storeWorkTime.setText(MyDateUtils.formatDataTime(item.getStoreWorkTime()));

                break;
            case 3:/*出厂订单*/
                logisticsWorkTimeLayout.setVisibility(View.GONE);
                storeNameLayout.setVisibility(View.GONE);

            case 4:
                batchText.setText("订单号");

                break;
        }
        storeTelLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EnterFactoryBean.ListBean items = mDataList.get(position);
                if(v.getId()== R.id.storeTel_layout) {
                    if (!CheckUtils.isEmpty(items.getStoreTel())) {
                        ActivityUtils.callActivity(mContext, items.getStoreTel());
                    }
                }
            }
        });
    }


}
